package com.xzq.erp.controller;


import com.xzq.erp.aspect.ApiOperationLog;
import com.xzq.erp.domain.dto.OrderDTO;
import com.xzq.erp.domain.dto.PageDTO;
import com.xzq.erp.domain.query.OrderPageQuery;
import com.xzq.erp.domain.query.SalesOpportunityPageQuery;
import com.xzq.erp.domain.vo.OrderVO;
import com.xzq.erp.domain.vo.SalesOpportunityVO;
import com.xzq.erp.service.IOrderService;
import com.xzq.erp.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author xzq
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/order")
@Tag(name = "订单相关接口")
@RequiredArgsConstructor
public class OrderController {

    private final IOrderService orderService;

    /**
     * 分页查询订单列表
     */
    @GetMapping("/list")
    @Operation(summary = "分页获取订单列表")
    @ApiOperationLog(description = "分页获取订单列表")
    @PreAuthorize("hasAuthority('order:list') || hasRole('ADMIN')")
    public Response<PageDTO<OrderVO>> getOrderList(@ParameterObject @Validated OrderPageQuery query) {
        return Response.success(orderService.getOrderList(query));
    }

    /**
     * 修改订单
     */
    @PutMapping
    @Operation(summary = "修改订单")
    @ApiOperationLog(description = "修改订单")
    @PreAuthorize("hasAuthority('order:update') || hasRole('ADMIN')")
    public Response<Void> update(@Validated @RequestBody OrderDTO orderDTO) {
        orderService.update(orderDTO);
        return Response.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping
    @Operation(summary = "批量删除订单")
    @ApiOperationLog(description = "批量删除订单")
    @PreAuthorize("hasAuthority('order:delete') || hasRole('ADMIN')")
    public Response<Void> delete(@RequestBody @NotEmpty List<Long> ids) {
        orderService.removeByIds(ids);
        return Response.success();
    }

}
